<?php
//Start session
require_once '../library/config.php';
require_once '../library/database.php';
/*
* comment here
*/
function resourceLang($key ){   
	$GLOBALS['curtlang']==""?$get_current_lang='en-US':$get_current_lang=$GLOBALS['curtlang'];   
	//Create query
	$qry="SELECT `res_value` FROM `tbl_resource_language` WHERE `res_key`='$key' and `resource_code`='$get_current_lang'";  
	$result=mysql_query($qry);
	if(mysql_num_rows($result) == 1) 
	{
		$langValue = mysql_fetch_assoc($result);
		echo $langValue["res_value"];
	}
	else
	{
		$key=ucfirst(str_replace("_"," ",$key));
		echo $key;
	}
	
	
}
/*
 * comment here
 */
function insertResourceLang($key,$val,$module,$langcode ){   
	//Create query
	$qry="INSERT INTO `pcshop`.`tbl_resource_language` (
            `resource_id` ,
            `resource_code` ,
            `res_key` ,
            `res_value` ,
            `res_module` ,
            `res_meta_field` ,
            `res_date_modify`
            )
            VALUES (
            NULL , '$langcode', '$key', '$val', '$module' , NULL , NULL
            ) ";
	$result=mysql_query($qry);
	if(!$result) 
	{
        return $errors['error']='Invalid query: ' . mysql_error();	        
	}  
	
	
}
/*
 * comment here
 */
function updateResourceLang($key,$val,$langcode){   
	//Create query
	$qry="UPDATE `tbl_resource_language` SET 
        `res_value`='$val',`res_date_modify`='' WHERE  `resource_code`='$langcode' and `res_key`='$key',";
	$result=mysql_query($qry);
	if(!$result) 
	{
        return $errors['error']='Invalid query: ' . mysql_error();	        
	}
    else
    {
        //success update
    }
    
	
	
}
/*
 * comment here
 */
function getResourceLang($key){   
    $data 			= array(); 		// array to pass back data   
	//Create query
	$qry="SELECT `res_value` FROM `tbl_resource_language` WHERE `res_key`='$key' and `resource_code`='vi-VN'";  
	$result=mysql_query($qry);
    if(!$result) 
	{
        return $errors['error']='Invalid query: ' . mysql_error();	        
	}
    if(mysql_num_rows($result) >= 1) 
	{
		$langValue = mysql_fetch_assoc($result);
        $data['vi']=$langValue["res_value"];
    }
	else
	{
		$data['vi']='resEmpty-VI';
	}
	$qry="SELECT `res_value` FROM `tbl_resource_language` WHERE `res_key`='$key' and `resource_code`='en-US'";  
	$result=mysql_query($qry);
    if(!$result) 
	{
        return $errors['error']='Invalid query: ' . mysql_error();	        
	}
    if(mysql_num_rows($result) >= 1) 
	{
		$langValue = mysql_fetch_assoc($result);
        $data['en']=$langValue["res_value"];
    }
	else
	{
		$data['en']='resEmpty-US';
	}
    
    return $data;   
    
    
}
/*
 * comment here
 */
function getResourceLangcode($key,$langcode){     
	//Create query
	$qry="SELECT `res_value` FROM `tbl_resource_language` WHERE `res_key`='$key' and `resource_code`='$langcode'";  
	$result=mysql_query($qry);
    if(!$result) 
	{
        return $errors['error']='Invalid query: ' . mysql_error();	        
	}
    if(mysql_num_rows($result) >= 1) 
	{
		$langValue = mysql_fetch_assoc($result);
      return  $data=$langValue["res_value"];
    }
	else
	{
		return 'resEmpty';
	}	
    
}
?>